import {
  getIndex
} from '../../api/index.js'
import {
  getNews
} from "../../api/news.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    $https: getApp().globalData.$https,
    focus: false,
    keyword: '',
    imgUrl: [{
        id: 0,
        img: '../../img/index/banner.jpg',
      },
      {
        id: 1,
        img: '../../img/index/banner.jpg',
      },
    ],
    indicatorDots: true,
    indicatorColor: '#838588',
    indicatorActiveColor: '#ffffff',
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    menuTapCurrent: 0,
    entryList: [ //快捷入口
      {
        id: 0,
        imgUrl: '../../img/index/rk_1.png',
        name: '经销商查询'
      },
      {
        id: 1,
        imgUrl: '../../img/index/rk_2.png',
        name: '服务商查询'
      },
      {
        id: 3,
        imgUrl: '../../img/index/rk_3.png',
        name: '运营商查询'
      },
      {
        id: 4,
        imgUrl: '../../img/index/rk_1.png',
        name: '服务创新'
      },
      {
        id: 5,
        imgUrl: '../../img/index/rk_5.png',
        name: '金融支持'
      },
      // {
      //   id:6,
      //   imgUrl:'../../img/index/rk_6.png',
      //   name:'金融计算器'
      // }
    ],
    carCategory: [],
    newsList: [],
    activeList: [],
    bannerList: [],
    newslist2: [],
    current:0,
    slideLeft:0 ,//滑块位置
  },
  getleft:function(e){
    console.log(e)
    this.setData({
      slideLeft: e.detail.scrollLeft
    })
  },
  changeswiper(current, source){
    this.setData({
      current:current.detail.current
    })
  },
  bannerurl(e) {
    var url = e.currentTarget.dataset.url
    if (url == '#' || url == '') {
      // wx.navigateTo({
      //   url: '../live/live',
      // })
    } else {
      wx.navigateTo({
        url: url,
      })
    }
  },
  jumpsearch: function (e) {
    const url = "/pages/searchWord/searchWord";
    wx.navigateTo({
      url: url,
    })
  },
  bindconfirm: function () {
    event.detail = {
      value
    }
  },
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  carDetail(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../carType/carType?id=' + id
    })
  },
  applicaClick(e) {
    // 快捷入口跳转
    if (e.currentTarget.dataset.index == 3) {
      wx.navigateTo({
        url: '../../packageA/service/service'
      })
    } else if (e.currentTarget.dataset.index == 0 || e.currentTarget.dataset.index == 1 || e.currentTarget.dataset.index == 2) {
      wx.navigateTo({
        url: '../../packageA/query/query?index=' + e.currentTarget.dataset.index
      })
    } else if (e.currentTarget.dataset.index == 4) {
      wx.navigateTo({
        url: '../../packageA/financial/index'
      })
    } else if (e.currentTarget.dataset.index == 5) {
      wx.showToast({
        title: '功能开发中...',
        icon: 'none'
      })
      // wx.navigateTo({
      //   url:'../../packageA/Calculator/Calculator'
      // })
    }
  },
  menuTap: function (e) {
    var current = e.currentTarget.dataset.current; //获取到绑定的数据
    //改变menuTapCurrent的值为当前选中的menu所绑定的数据
    this.setData({
      menuTapCurrent: current
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getIndex()
    this.getNewsList()
    wx.stopPullDownRefresh()
  },
  async getNewsList() {
    var res = await getNews({
      type: 1
    })
    this.setData({
      newslist2: res.rows
    })
  },
  // 获取首页数据
  async getIndex() {
    var res = await getIndex()
    this.setData({
      bannerList: res.banner,
      newsList: res.news,
      carCategory: res.carCategory,
      activeList: res.topic
    })
  },
  jumpactivity(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/packageA/activityDetails/activityDetails?id=' + id,
    })
  },
  jumpnews(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/packageA/Newsdetail/Newsdetail?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onLoad()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '远程汽车',
      path: '/pages/home/home',
      imageUrl:'../../img/share/index.jpg'
    }
  }
})